package com.ncloud.crm.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.common.enmus.ResultEnum;
import com.ncloud.common.exception.UserException;
import com.ncloud.crm.entity.Delegation;
import com.ncloud.crm.mapper.DelegationMapper;
import com.ncloud.crm.service.DelegationService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DelegationServiceImpl implements DelegationService {
	
	private static final Logger logger = LogManager.getLogger(DelegationServiceImpl.class);
	
	@Autowired
	private DelegationMapper delegationMapper;


	public JSONArray getId(JSONObject json) {
		return null;
	}

	@Override
	public JSONArray getDelegationByDefinition(String key) {
		if(key == null){
			throw new UserException(ResultEnum.PARAM_ERROR);
		}
		try {
			List<Delegation> delegationList = delegationMapper.getDelegationByDefinition(key);
			return JSON.parseArray(JSON.toJSONString(delegationList));
		}catch (RuntimeException e){
			e.printStackTrace();
			throw new UserException(ResultEnum.DATABASE_ERROR);
		}


	}
}
